package com.example.forumsystem.controller;

import com.example.forumsystem.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "测试类相关接口")
/*表示返回的结果是数据 而不是URL*/
@RestController
/*定义一级映射路径 目录test*/
@RequestMapping("/test")
public class TestController {
    @ApiOperation("测试接口1，显示hello,Spring boot...")
   @GetMapping("/hello")
    public String hello(){
        return "hello,Spring boot...";
    }

    @ApiOperation("测试接口4，按传入的姓名显示你好信息")
    @PostMapping("/helloByName")
    public String helloByName(@ApiParam("姓名") @RequestParam("name") String name){
        return "hello: "+name;
    }

    @ApiOperation("测试接口2，显示这是⼀个Exception")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是⼀个Exception");
    }
    @ApiOperation("测试接口3，显示这是⼀个⾃定义的ApplicationException")
    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }
}
